package com.lzk.工厂模式.抽象工厂.order;


import com.lzk.工厂模式.抽象工厂.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * author: 刘中魁
 */
public class OrederPizza {
    AbsFactory factory;
    //构造器
    public OrederPizza(AbsFactory factory){
        setFactory(factory);
    }

    private void setFactory(AbsFactory factory) {
        Pizza pizza = null;
        String orderType = ""; //用户输入
        this.factory = factory;

        do {
            orderType = getType();
            // factory 可能是北京的工厂类 也可能是伦敦的工厂类
            pizza = factory.createPizza(orderType);

            if (pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }

        }while (true);

    }


    //写一个方法可以动态的获取客户希望订购的披萨种类
    private String getType(){
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
}
